package com.zyh.assessments.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zyh.assessments.domain.Assessments;
import com.zyh.assessments.service.AssessmentsService;
import com.zyh.common.core.controller.BaseController;
import com.zyh.common.core.domain.AjaxResult;
import com.zyh.exam.domain.ExamPaper;
import com.zyh.exam.service.IExamPaperService;
import com.zyh.question.domain.ExamQuestion;
import com.zyh.question.service.IExamQuestionService;
import com.zyh.record.service.ExamRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 测评卷详情Controller
 *
 * @author ZYH
 * @version 1.0
 * @date 2025-02-23
 */
@RestController
@RequestMapping("/assessments/assessments")
public class AssessmentsController extends BaseController {


    @Autowired
    private IExamPaperService examPaperService;


    @Autowired
    private IExamQuestionService examQuestionService;

    @Autowired
    private AssessmentsService assessmentService;


    /**
     * 获取测评卷封面信息
     *
     * @return
     */
    // @PreAuthorize("@ss.hasPermi('assessments:assessments:list')")
    @GetMapping("/getPaperPreview")
    public AjaxResult getPaperPreview() {
        // 查询条件-->查询已发布的测评卷
        List<ExamPaper> examPaperList = examPaperService.list(
                new LambdaQueryWrapper<ExamPaper>()
                        .eq(ExamPaper::getIsPublished, "1")
                        .eq(ExamPaper::getDelFlag, "0"));
        return AjaxResult.success(examPaperList);
    }


    /**
     * 根据测评卷id获取测评卷详情和试题详情
     *
     * @param paperId
     * @return
     */
    // @PreAuthorize("@ss.hasPermi('assessments:assessments:exam')")
    @GetMapping("/getPaperDetails/{paperId}")
    public AjaxResult getPaperDetails(@PathVariable("paperId") Long paperId) {
        Assessments assessments = new Assessments();
        // 根据id查询测评卷
        ExamPaper examPaper = examPaperService.selectExamPaperById(paperId);
        assessments.setExamPaper(examPaper);
        // 根据id查询试题
        List<ExamQuestion> examQuestionList = examQuestionService.selectExamQuestionByPaperId(paperId);
        assessments.setExamQuestions(examQuestionList);
        return AjaxResult.success(assessments);
    }

    /**
     * 获取历史记录
     *
     * @return
     */
    @GetMapping("/getHistoryList")
    public AjaxResult getHistoryList() {
        return assessmentService.getHistoryList();
    }
}